package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    //套餐分页查询
    @GetMapping("/setmeal/page")
    public ResultInfo findByPage(
            @RequestParam(value = "page",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,
            String name){
        //
        Page<Setmeal> page = setmealService.findByPage(pageNum,pageSize,name);
        //
        return ResultInfo.success(page);
    }



    //套餐新增
    @PostMapping("/setmeal")
    public ResultInfo save(@RequestBody Setmeal setmeal){//接受参数
        setmealService.sava(setmeal);//调用service方法
        return ResultInfo.success();

    }

    //套餐起售停售
    @PostMapping("/setmeal/status/{status}")
    public ResultInfo updateStatus(@PathVariable("status")Integer status,
                                   @RequestParam List<Long> ids){//接受参数
        setmealService.updateStatus(status,ids);

        return ResultInfo.success();
    }

    //套餐删除
    @DeleteMapping("/setmeal")
    public ResultInfo deleteBatchIds(@RequestParam List<Long> ids){//接受参数

        setmealService.deleteBatchIds(ids);
        return ResultInfo.success();
    }
    //套餐修改回显
    @GetMapping("/setmeal/{id}")
    public ResultInfo findById(@PathVariable("id") Long id){
        Setmeal setmeal = setmealService.findById(id);
        return ResultInfo.success(setmeal);
    }
    //套餐修改
    @PutMapping("/setmeal")
    public ResultInfo update(@RequestBody Setmeal setmeal){//接受参数
        setmealService.update(setmeal);
        return ResultInfo.success();

    }
}
